#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>

int arr[200000];
long long count = 0;

struct num
{
	long time;
	int num1;
};
struct num nums[2000000];

void quickly_sort(int* arr, int begin, int end)
{
	if (end <= begin)
		return;
	int tmp = rand() % (end - begin + 1) + begin;
	int left = begin;
	int right = end;

	int hole = arr[tmp];
	arr[tmp] = arr[left];
	arr[left] = hole;
	while (left < right)
	{
		//
		while (left < right && arr[right] <= hole)
			right--;

		//
		arr[left] = arr[right];

		//
		while (left < right && arr[left] >= hole)
			left++;


		arr[right] = arr[left];
	}
	int mitti = left;
	arr[mitti] = hole;
	quickly_sort(arr, begin, mitti - 1);
	quickly_sort(arr, mitti + 1, end);
}

long long two_find(struct num* str, int n,int i ,int k)
{
	int left = 0;
	int right = k;
	while(left<=right)
	{
		int mid = (left + right) / 2;
		
		if (n > str[mid].num1)
		{
			right = mid - 1;
		
		}
		else if (n < str[mid].num1)
		{
			left = mid + 1;
		}

		else if (n == str[mid].num1)
			return (1LL * str[i].time*str[mid].time);
	}
	return 0;
}



int main()
{
	srand(0);
	int n = 0;
	int c = 0;
	scanf("%d %d", &n, &c);

	int i = 0;
	int j = 0;
	for (i = 0; i < n; i++)
		scanf("%d", &arr[i]);

	quickly_sort(arr, 0, n - 1);

	int k = 0;
	nums[0].num1 = arr[0];
	nums[0].time = 1;
	for (i = 1; i < n; i++)
	{
		if (arr[i] == nums[k].num1)
			nums[k].time++;
		else
		{
			nums[++k].num1 = arr[i];
			nums[k].time = 1;
		}
	}

	for (i = 0; i < k; i++)
	{
		if (nums[i].num1 - nums[k].num1 < c)
			break;
		count +=	two_find(nums ,  (nums[i].num1 - c) , i ,  k);
	}

	printf("%lld", count);
	return 0;
}